﻿using BasicInformation.API.Application.Command.LineCommand;
using BasicInformation.Infrastructure.Interface;
using MediatR;

namespace BasicInformation.API.Application.CommandHandler.LineCommandHandler
{
    public class LineBatchDeleteCommandHandler : IRequestHandler<LineBatchDeleteCommand, int>
    {
        private readonly ILineRepository lineRepository;

        public LineBatchDeleteCommandHandler(ILineRepository lineRepository)
        {
            this.lineRepository = lineRepository;
        }

        public async Task<int> Handle(LineBatchDeleteCommand request, CancellationToken cancellationToken)
        {
            var Id = request.Ids.Split(',').Select(x => Convert.ToInt32(x)).ToArray();
            var list = await lineRepository.GetListInfo(x => Id.Contains(x.Id));
            foreach (var item in list)
            {
                item.IsDel = true;
            }
            return await lineRepository.UpdateRange(list);
        }
    }
}
